package com.software.demo1.test;

import com.software.demo1.entity.User;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import java.util.Date;
import java.util.UUID;

public class Run {
    public static void main(String[] args) {
        Configuration cfg = new Configuration();
        cfg.configure();

        SessionFactory sessionFactory = cfg.buildSessionFactory();
        Session session = sessionFactory.openSession();

        Transaction transaction = session.beginTransaction();

        // 处理业务逻辑
        User user = new User();
        user.setUserId(UUID.randomUUID().toString());
        user.setUserName("class-one-demo1");
        user.setPassword("class-one-demo1");
        user.setLoginTime(new Date());
        session.save(user);

        transaction.commit();
        session.close();
        sessionFactory.close();
    }
}
